package com.gomyb.storage.model;

import com.aliyun.oss.OSSClient;

import java.io.InputStream;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/3/6 19:24
 */
public enum StorageSource {
    OSS("oss") {
        @Override
        public boolean upload(CloudStorageAuth cloudStorageAuth, InputStream inputStream, String fileName, String path) {
            // 创建OSSClient实例。
            OSSClient ossClient = new OSSClient(cloudStorageAuth.getEndpoint(), cloudStorageAuth.getAccessKeyId(), cloudStorageAuth.getAccessKeySecret());

            // 上传内容到指定的存储空间（bucketName）并保存为指定的文件名称（objectName）。
            ossClient.putObject(cloudStorageAuth.getBucketName(), path + "/" + fileName, inputStream);

            // 关闭OSSClient。
            ossClient.shutdown();
            return false;
        }
    },
    QI_NIU("qiniu") {
        @Override
        public boolean upload(CloudStorageAuth cloudStorageAuth, InputStream inputStream, String fileName, String path) {


            return false;
        }
    };

    StorageSource(String code) {
        this.code = code;
    }

    /**
     * 上传
     */
    public abstract boolean upload(CloudStorageAuth cloudStorageAuth, InputStream inputStream, String fileName, String path);

    private String code;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}